package com.e2oto.seller.modules.seller.ui;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;

import com.e2oto.seller.common.base.BaseActivity;
import com.e2oto.seller.modules.seller.adapter.MainPageAdapter;
import com.e2oto.seller.R;
import com.gyf.barlibrary.ImmersionBar;

import butterknife.BindView;
import butterknife.OnClick;


public class HomeActivity extends BaseActivity {

    @BindView(R.id.main_view_pager)
    ViewPager viewPager;
    @BindView(R.id.home_pending_rl)
    RelativeLayout pendingTab;
    @BindView(R.id.home_shop_rl)
    RelativeLayout shopTab;
    @BindView(R.id.home_order_rl)
    RelativeLayout orderTab;

    @BindView(R.id.home_mine_rl)
    RelativeLayout mineTab;

    private MainPageAdapter mainPageAdapter;

    @Override
    protected void afterView(Bundle savedInstanceState) {
        mainPageAdapter = new MainPageAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mainPageAdapter);
        pendingTab.setSelected(true);

    }

    @Override
    protected int getContentView() {
        return R.layout.activity_home;
    }

    @Override
    protected void beforeView() {
        //在fragment中使用 必须现在宿主Activity中初始化
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.init();
    }


    @OnClick({R.id.home_pending_rl, R.id.home_shop_rl, R.id.home_mine_rl, R.id.home_order_rl})
    public void onClickTabs(View v) {
        //清除所有选中状态
        pendingTab.setSelected(false);
        shopTab.setSelected(false);
        mineTab.setSelected(false);
        int position = 0;
        switch (v.getId()) {
            case R.id.home_pending_rl:
                position = 0;
                pendingTab.setSelected(true);
                break;
            case R.id.home_shop_rl:
                position = 1;
                shopTab.setSelected(true);
                break;
            case R.id.home_order_rl:
                position = 2;
                orderTab.setSelected(true);
                break;
            case R.id.home_mine_rl:
                position = 3;
                mineTab.setSelected(true);
                break;
        }
        viewPager.setCurrentItem(position);
    }


}
